package com.tuyrt.`as`.proj.main.model

import android.os.Parcelable
import android.text.TextUtils
import kotlinx.android.parcel.Parcelize
import java.io.Serializable

/**
 *  HomePage 页的模型
 */

data class HomeModel(val bannerList: List<HomeBanner>?, val subcategoryList: List<Subcategory>?, val goodsList: List<GoodsModel>?) :
    Serializable


/*{
    "categoryId": "1",
    "categoryName": "热门",
    "goodsCount": "1"
}*/
data class TabCategory(val categoryId: String, val categoryName: String, val goodsCount: String) : Serializable

/*{
    "id": "10",
    "sticky": 1,
    "type": "recommend",
    "title": "好课推荐",
    "subtitle": "Flutter高级进阶实战 仿哔哩哔哩APP",
    "url": "https://coding.imooc.com/class/487.html",
    "cover": "https://img4.mukewang.com/604ec1a30001d21b17920764.jpg",
    "createTime": "2021-03-15 11:51:12"
}*/
data class HomeBanner(
    val cover: String,
    val createTime: String,
    val id: String,
    val sticky: Int,
    val subtitle: String,
    val title: String,
    val type: String,
    val url: String,
) : Serializable {
    companion object {
        const val TYPE_GOODS = "goods"
        const val TYPE_RECOMMEND = "recommend"
    }
}

/*{
    "subcategoryId": "1",
    "groupName": null,
    "categoryId": "1",
    "subcategoryName": "限时秒杀",
    "subcategoryIcon": "https://o.devio.org/images/as/images/2018-05-16/26c916947489c6b2ddd188ecdb54fd8d.png",
    "showType": "1"
}*/
data class Subcategory(
    val categoryId: String,
    val groupName: String,
    val showType: String,
    val subcategoryIcon: String,
    val subcategoryId: String,
    val subcategoryName: String,
) : Serializable

/*{
    "goodsId": "1574944087516",
    "categoryId": "7",
    "hot": true,
    "sliderImages": [
    {
        "url": "https://o.devio.org/images/as/goods/images/2019-11-20/b18efa71-0637-484a-b5ec-90abb62cddf1.jpg",
        "type": 1
    },
    {
        "url": "https://o.devio.org/images/as/goods/images/2019-11-11/98989a99-5a84-4141-ac92-d5fa597239d4.jpg",
        "type": 1
    },
    {
        "url": "https://o.devio.org/images/as/goods/images/2019-10-30/ef900d27-9ad7-49eb-97f2-d1cde52df189.jpg",
        "type": 1
    }
    ],
    "marketPrice": "",
    "groupPrice": "19.98",
    "completedNumText": "已拼5074件",
    "goodsName": "新西兰安佳动物无盐黄油散装500g烘焙原料曲奇饼干面包牛排家黄油",
    "tags": "全场包邮 7天无理由退货 48小时发货 假一赔十",
    "joinedAvatars": null,
    "createTime": "2019-11-28 20:28:07",
    "sliderImage": "https://o.devio.org/images/as/goods/images/2019-11-20/b18efa71-0637-484a-b5ec-90abb62cddf1.jpg"
}*/
@Parcelize
data class GoodsModel(
    val categoryId: String,
    val completedNumText: String,
    val createTime: String,
    val goodsId: String,
    val goodsName: String,
    val groupPrice: String?,
    val hot: Boolean,
    val joinedAvatars: List<SliderImage>?,
    val marketPrice: String?,
    val sliderImage: String?,
    val sliderImages: List<SliderImage>?,
    val tags: String?,
) : Serializable, Parcelable

@Parcelize
data class SliderImage(
    val type: Int,
    val url: String,
) : Serializable,Parcelable

data class GoodsList(
    val total: Int,
    val list: List<GoodsModel>,
)

fun selectPrice(groupPrice: String?, marketPrice: String?): String {
    var price = if (TextUtils.isEmpty(marketPrice)) groupPrice else marketPrice
    if (price?.startsWith("¥") != true) {
        price = "¥".plus(price)
    }
    return price
}